global class CCWS{

Webservice static Sales_Contract__c getPlanNameMap(String planDocumentId, String Url){

  Map<String, String> NameVal =  new Map<String, String>(); 
  Integer i = 0; 
  Integer count = 0;
  Integer k = 0;
  Sales_Contract__c[] planDocument=null;
  
  Remote_IP_Address__c[] rip = [select IPAddress__c from Remote_IP_Address__c limit 1];
  
  TCMPCallidusCom1.PlanDataServicesHttpPort cald = new TCMPCallidusCom1.PlanDataServicesHttpPort(); 
  cald.inputHttpHeaders_x = new Map<String, String>();
  cald.outputHttpHeaders_x = new Map<String, String>();
  if(rip.size() > 0)
      cald.endpoint_x = rip[0].IPAddress__c+'/TCWSWAR/services/PlanDataServices';
 
  String su = UserInfo.getSessionId();
  cald.inputHttpHeaders_x.put('sessionID', userinfo.getSessionId());
  cald.inputHttpHeaders_x.put('serverURL', Url);
  
  TCMPCallidusCom1.ArrayOfPlanData arrpdata = new TCMPCallidusCom1.ArrayOfPlanData();
          
  TCMPCallidusCom1.PlanData pdata = new TCMPCallidusCom1.PlanData();
  TCMPCallidusCom1.PlanDTO pdto = new TCMPCallidusCom1.PlanDTO();
  TCMPCallidusCom1.ParticipantDTO partDTO = new TCMPCallidusCom1.ParticipantDTO();
  TCMPCallidusCom1.PositionDTO postDTO = new TCMPCallidusCom1.PositionDTO();
  TCMPCallidusCom1.QuotaDTO quotDTO = new TCMPCallidusCom1.QuotaDTO();
  TCMPCallidusCom1.TerritoryDTO terriDTO = new TCMPCallidusCom1.TerritoryDTO();
  TCMPCallidusCom1.TitleDTO titlDTO = new TCMPCallidusCom1.TitleDTO();
  TCMPCallidusCom1.FixedValueDTO fixedDTO = new TCMPCallidusCom1.FixedValueDTO();
  TCMPCallidusCom1.RateTableDTO rateDTO = new TCMPCallidusCom1.RateTableDTO();
  
  planDocument = [SELECT Id, Name, PayeeID__c, FirstName__c, LastName__c, UserID__c, UserRoleId__c, UserRoleName__c, Name1__c, Name2__c, Name3__c, Name4__c, Name5__c, Name6__c, Name7__c, Name8__c, Name9__c, Name10__c, Name11__c, Name12__c, Name13__c, Name14__c, Name15__c, Name16__c, Name17__c, Name18__c, Name19__c, Name20__c, Name21__c, Name22__c, Name23__c, Name24__c, Name25__c, Name26__c, Name27__c, Name28__c, Name29__c, Name30__c, Value1__c, Value2__c, Value3__c, Value4__c, Value5__c, Value6__c, Value7__c, Value8__c, Value9__c, Value10__c, Value11__c, Value12__c, Value13__c, Value14__c, Value15__c, Value16__c, Value17__c, Value18__c, Value19__c, Value20__c, Value21__c, Value22__c, Value23__c, Value24__c, Value25__c, Value26__c, Value27__c, Value28__c, Value29__c, Value30__c FROM Sales_Contract__c sc where sc.Id=:planDocumentId];

  if(planDocument.size() > 0)
  {
      try{
      arrpdata = cald.getPlanDataByPayee(planDocument[0].PayeeID__c, '1/1/2008');
      }catch(Exception excep){
          planDocument[0].UserRoleName__c = excep.getMessage();
       return planDocument[0];
       }
  
  try
  {
      pdto = arrpdata.PlanData[0].planList.PlanDTO[0];
      partDTO = arrpdata.PlanData[0].participantList.ParticipantDTO[0];
      postDTO = arrpdata.PlanData[0].positionList.PositionDTO[0];
    
      NameVal.put('Plan.Name', pdto.name);
      NameVal.put('Plan.Desciption',pdto.description);
      NameVal.put('Plan.Effectiveenddate', null);
      if (pdto.effectiveEndDate != null){
           NameVal.put('Plan.Effectiveenddate',pdto.effectiveEndDate.format());    
      }
    
      NameVal.put('Plan.Effectivestartdate', null);
      if (pdto.effectiveStartDate != null){
            NameVal.put('Plan.Effectivestartdate', pdto.effectiveStartDate.format());
      }
     
      NameVal.put('Participant.Businessunit', partDTO.businessUnit);
      NameVal.put('Participant.Firstname',partDTO.firstName);
      NameVal.put('Participant.Lastname', partDTO.lastName);
    
      NameVal.put('Participant.Hiredate', null);
      if (partDTO.hireDate != null){
          NameVal.put('Participant.Hiredate', partDTO.hireDate.format());
      }
       
      NameVal.put('Participant.Taxid', partDTO.taxId);
      if(partDTO.genericAttributes.GenericAttributeDTO != null)
      {
          count = partDTO.genericAttributes.GenericAttributeDTO.size();
          for (i=0; i < count; i++){
           NameVal.put('Participant.Genericattribute' + i + '.Name', partDTO.genericAttributes.GenericAttributeDTO[i].name);
           NameVal.put('Participant.Genericattribute' + i + '.Overridename', Partdto.genericAttributes.GenericAttributeDTO[i].overrideName);
           NameVal.put('Participant.Genericattribute' + i + '.Value', partDTO.genericAttributes.GenericAttributeDTO[i].value); 
          }
      }
      NameVal.put('Participant.Salary', '');
      if(partDTO.salary != null)
          NameVal.put('Participant.Salary', partDTO.salary.value);

      NameVal.put('Participant.Salaryunittypename', '');
      if(partDTO.salary != null)
          NameVal.put('Participant.Salaryunittypename', partDTO.salary.unitTypeName);
          
      NameVal.put('Position.Description', postDTO.description);
      NameVal.put('Position.Name', postDTO.name);
      NameVal.put('Position.Planname', postDTO.planName);
      NameVal.put('Position.Title', postDTO.title);

      NameVal.put('Position.Targetcompensation', '');
      if(postDTO.targetCompensation != null)
          NameVal.put('Position.Targetcompensation', postDTO.targetCompensation.value);

      NameVal.put('Position.Targetcompensationunittype', '');

      if(postDTO.targetCompensation != null)
          NameVal.put('Position.Targetcompensationunittype', postDTO.targetCompensation.unitTypeName);
      
      if(postDTO.genericAttributes.GenericAttributeDTO != null)
      {
          count = postDTO.genericAttributes.GenericAttributeDTO.size();
          for (i=0; i < count; i++){
          NameVal.put('Position.Genericattribute' + i + '.Name', postDTO.genericAttributes.GenericAttributeDTO[i].name);
          NameVal.put('Position.Genericattribute' + i + '.Overridename', postDTO.genericAttributes.GenericAttributeDTO[i].overrideName);
          NameVal.put('Position.Genericattribute' + i + '.Value', postDTO.genericAttributes.GenericAttributeDTO[i].value); 
          }
      }
      
      if(arrpdata.PlanData[0].quotaList.QuotaDTO != null)
      {
          count = arrpdata.PlanData[0].quotaList.QuotaDTO.size();
          for (i=0; i < count; i++){
           NameVal.put('Quota' + i + '.Name', arrpdata.PlanData[0].quotaList.QuotaDTO[i].name);
           NameVal.put('Quota' + i + '.Description', arrpdata.PlanData[0].quotaList.QuotaDTO[i].description);
           NameVal.put('Quota' + i + '.Periodtype', arrpdata.PlanData[0].quotaList.QuotaDTO[i].periodtype);
           NameVal.put('Quota' + i + '.Periodvalue', arrpdata.PlanData[0].quotaList.QuotaDTO[i].periodValue);
           NameVal.put('Quota' + i + '.Value', arrpdata.PlanData[0].quotaList.QuotaDTO[i].value);
           NameVal.put('Quota' + i + '.Variablename', arrpdata.PlanData[0].quotaList.QuotaDTO[i].variableName);
          }
      }
      
      if(arrpdata.PlanData[0].territoryList.TerritoryDTO != null)
      {
          count = arrpdata.PlanData[0].territoryList.TerritoryDTO.size();
          for (i=0; i < count; i++){
           NameVal.put('Terrotory' + i + '.Name', arrpdata.PlanData[0].territoryList.TerritoryDTO[i].name);
           NameVal.put('Terrotory' + i + '.Description', arrpdata.PlanData[0].territoryList.TerritoryDTO[i].description);
           NameVal.put('Terrotory' + i + '.Definition', arrpdata.PlanData[0].territoryList.TerritoryDTO[i].definition);
           NameVal.put('Terrotory' + i + '.Variablename', arrpdata.PlanData[0].territoryList.TerritoryDTO[i].variableName);
          }
      }//end of if
      
      titlDTO = arrpdata.PlanData[0].titleList.TitleDTO[0];
      NameVal.put('Title.Description', titlDTO.description);
      NameVal.put('Title.Name', titlDTO.name);
      
      if(titlDTO.genericAttributes.GenericAttributeDTO != null)
      {
          count = titlDTO.genericAttributes.GenericAttributeDTO.size();
          for (i=0; i < count; i++){
           NameVal.put('Title.Genericattribute' + i + '.Name', titlDTO.genericAttributes.GenericAttributeDTO[i].name);
           NameVal.put('Title.Genericattribute' + i + '.Overridename', titlDTO.genericAttributes.GenericAttributeDTO[i].overrideName);
           NameVal.put('Title.Genericattribute' + i + '.Value', titlDTO.genericAttributes.GenericAttributeDTO[i].value); 
          }
      } 
      
      if(arrpdata.PlanData[0].fixedValueList.FixedValueDTO != null)
      {
          count = arrpdata.PlanData[0].fixedValueList.FixedValueDTO.size();
          for (i=0; i < count; i++){
           NameVal.put('Fixedvalue' + i + '.Name', arrpdata.PlanData[0].fixedValueList.FixedValueDTO[i].name);
           NameVal.put('Fixedvalue' + i + '.Description', arrpdata.PlanData[0].fixedValueList.FixedValueDTO[i].description);
           NameVal.put('Fixedvalue' + i + '.Value', arrpdata.PlanData[0].fixedValueList.FixedValueDTO[i].value);
           NameVal.put('Fixedvalue' + i + '.Variablename', arrpdata.PlanData[0].fixedValueList.FixedValueDTO[i].variableName);
          }
      }
      
      Integer subCount = 0;
      Integer j = 0;
      if(arrpdata.PlanData[0].rateTableList.RateTableDTO != null)
      {
          count = arrpdata.PlanData[0].rateTableList.RateTableDTO.size();
          for (i=0; i < count; i++){
           NameVal.put('Ratetable' + i + '.Name', arrpdata.PlanData[0].rateTableList.RateTableDTO[i].name);
           NameVal.put('Ratetable' + i + '.Description', arrpdata.PlanData[0].rateTableList.RateTableDTO[i].description);
           NameVal.put('Ratetable' + i + '.Variablename', arrpdata.PlanData[0].rateTableList.RateTableDTO[i].variableName);
        
           if(arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel != null)
           {
               subCount = arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel.size();
               for(j=0; j<subCount; j++){
                 NameVal.put('Ratelevel' + j + '.Rate', arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel[j].rate);
                 NameVal.put('Ratelevel' + j + '.Operator', arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel[j].operator);
                 NameVal.put('Ratelevel' + j + '.Attainment', arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel[j].attainment);
               }//end of inner for
            }//end of inner if
          }//end of outer for
       }//end of outer if
    }//end of try
    catch(Exception e)
    {
    
    }
    
 if (planDocument[0].Name1__c!=null){
      planDocument[0].Value1__c= NameVal.get(planDocument[0].Name1__c);
      }
      if (planDocument[0].Name2__c!=null){
      planDocument[0].Value2__c= NameVal.get(planDocument[0].Name2__c);
      }
      if (planDocument[0].Name3__c!=null){
      planDocument[0].Value3__c= NameVal.get(planDocument[0].Name3__c);
      }
      if (planDocument[0].Name4__c!=null){
      planDocument[0].Value4__c= NameVal.get(planDocument[0].Name4__c);
      }
      if (planDocument[0].Name5__c!=null){
      planDocument[0].Value5__c= NameVal.get(planDocument[0].Name5__c);
      }
      if (planDocument[0].Name6__c!=null){
      planDocument[0].Value6__c= NameVal.get(planDocument[0].Name6__c);
      }
      if (planDocument[0].Name7__c!=null){
      planDocument[0].Value7__c= NameVal.get(planDocument[0].Name7__c);
      }
      if (planDocument[0].Name8__c!=null){
      planDocument[0].Value8__c= NameVal.get(planDocument[0].Name8__c);
      }
      if (planDocument[0].Name9__c!=null){
      planDocument[0].Value9__c= NameVal.get(planDocument[0].Name9__c);
      }
      if (planDocument[0].Name10__c!=null){
      planDocument[0].Value10__c= NameVal.get(planDocument[0].Name10__c);
      }
      if (planDocument[0].Name11__c!=null){
      planDocument[0].Value11__c= NameVal.get(planDocument[0].Name11__c);
      }
      if (planDocument[0].Name12__c!=null){
      planDocument[0].Value12__c= NameVal.get(planDocument[0].Name12__c);
      }
      if (planDocument[0].Name13__c!=null){
      planDocument[0].Value13__c= NameVal.get(planDocument[0].Name13__c);
      }
      if (planDocument[0].Name14__c!=null){
      planDocument[0].Value14__c= NameVal.get(planDocument[0].Name14__c);
      }
      if (planDocument[0].Name15__c!=null){
      planDocument[0].Value15__c= NameVal.get(planDocument[0].Name15__c);
      }
      if (planDocument[0].Name16__c!=null){
      planDocument[0].Value16__c= NameVal.get(planDocument[0].Name16__c);
      }
      if (planDocument[0].Name17__c!=null){
      planDocument[0].Value17__c= NameVal.get(planDocument[0].Name17__c);
      }
      if (planDocument[0].Name18__c!=null){
      planDocument[0].Value18__c= NameVal.get(planDocument[0].Name18__c);
      }
      if (planDocument[0].Name19__c!=null){
      planDocument[0].Value19__c= NameVal.get(planDocument[0].Name19__c);
      }
      if (planDocument[0].Name20__c!=null){
      planDocument[0].Value20__c= NameVal.get(planDocument[0].Name20__c);
      }
      if (planDocument[0].Name21__c!=null){
      planDocument[0].Value21__c= NameVal.get(planDocument[0].Name21__c);
      }
      if (planDocument[0].Name22__c!=null){
      planDocument[0].Value22__c= NameVal.get(planDocument[0].Name22__c);
      }
      if (planDocument[0].Name23__c!=null){
      planDocument[0].Value23__c= NameVal.get(planDocument[0].Name23__c);
      }
      if (planDocument[0].Name24__c!=null){
      planDocument[0].Value24__c= NameVal.get(planDocument[0].Name24__c);
      }
      if (planDocument[0].Name25__c!=null){
      planDocument[0].Value25__c= NameVal.get(planDocument[0].Name25__c);
      }
      if (planDocument[0].Name26__c!=null){
      planDocument[0].Value26__c= NameVal.get(planDocument[0].Name26__c);
      }
      if (planDocument[0].Name27__c!=null){
      planDocument[0].Value27__c= NameVal.get(planDocument[0].Name27__c);
      }
      if (planDocument[0].Name28__c!=null){
      planDocument[0].Value28__c= NameVal.get(planDocument[0].Name28__c);
      }
      if (planDocument[0].Name29__c!=null){
      planDocument[0].Value29__c= NameVal.get(planDocument[0].Name29__c);
      }
      if (planDocument[0].Name30__c!=null){
      planDocument[0].Value30__c= NameVal.get(planDocument[0].Name30__c);
      }  
      planDocument[0].isWSCall__c=true;
      try{
      update planDocument;
      }catch(DmlException dme){
       
      } 
      return planDocument[0]; 
    }
    return new Sales_Contract__c();
}


Webservice static String[] getPlanNamearr(String payeeId, String effectiveDate, String Url){

  String[] nvpair = new String[250];
  String[] nameFields = new List<String>();
  Integer nfCt = 0;
   
  Integer i = 0; 
  Integer count = 0;

  Remote_IP_Address__c[] rip = [select IPAddress__c from Remote_IP_Address__c limit 1];
    
  TCMPCallidusCom1.PlanDataServicesHttpPort cald = null;
  
  try
  {
      cald = new TCMPCallidusCom1.PlanDataServicesHttpPort(); 
      if(cald == null)
      {
         String[] s = new String[]{'TCMP1  : TCMPCallidusCom1.PlanDataServicesHttpPort is null === CALD : '+cald};
         return s;
      }
      cald.inputHttpHeaders_x = new Map<String, String>();
      cald.outputHttpHeaders_x = new Map<String, String>();
      if(rip.size() > 0)
          cald.endpoint_x = rip[0].IPAddress__c+'/TCWSWAR/services/PlanDataServices';
  }
  catch(Exception e)
  {
      System.debug('TCMP  : '+e.getMessage()+' CALD : '+cald);
      String[] s = new String[]{'TCMP  : '+e.getMessage()+' CALD : '+cald};
        
      return s;
  }
  String su = UserInfo.getSessionId();
   
  cald.inputHttpHeaders_x.put('sessionID', userinfo.getSessionId());
  cald.inputHttpHeaders_x.put('serverURL', Url);  
  
  TCMPCallidusCom1.ArrayOfPlanData arrpdata = new TCMPCallidusCom1.ArrayOfPlanData();

  TCMPCallidusCom1.PlanData pdata = new TCMPCallidusCom1.PlanData();
  TCMPCallidusCom1.PlanDTO pdto = new TCMPCallidusCom1.PlanDTO();
  TCMPCallidusCom1.ParticipantDTO partDTO = new TCMPCallidusCom1.ParticipantDTO();
  TCMPCallidusCom1.PositionDTO postDTO = new TCMPCallidusCom1.PositionDTO();
  TCMPCallidusCom1.QuotaDTO quotDTO = new TCMPCallidusCom1.QuotaDTO();
  TCMPCallidusCom1.TerritoryDTO terriDTO = new TCMPCallidusCom1.TerritoryDTO();
  TCMPCallidusCom1.TitleDTO titlDTO = new TCMPCallidusCom1.TitleDTO();
  TCMPCallidusCom1.FixedValueDTO fixedDTO = new TCMPCallidusCom1.FixedValueDTO();
  TCMPCallidusCom1.RateTableDTO rateDTO = new TCMPCallidusCom1.RateTableDTO();

    try
    {
      arrpdata = cald.getPlanDataByPayee(payeeId, effectiveDate);   
    }
    catch(Exception e)
    {
        String[] s = new String[]{e.getMessage()};
        
        return s;
    }
 
   try
   {      
      pdto = arrpdata.PlanData[0].planList.PlanDTO[0];
   }
   catch(Exception e)
   {
      System.debug('TCMP3  : '+e.getMessage()+' CALD : '+cald);
      String[] s = new String[]{'TCMP3  : '+e.getMessage()+' CALD : '+cald+'  PDTO : '+pdto};
        
      return s;
   }
 
  try
  {      
      partDTO = arrpdata.PlanData[0].participantList.ParticipantDTO[0];
  }
  catch(Exception e)
  {
      System.debug('TCMP4  : '+e.getMessage()+' CALD : '+cald);
      String[] s = new String[]{'TCMP4  : '+e.getMessage()+' CALD : '+cald+' PartDTO : '+partDTO};
        
      return s;
  }
      
  try
  {      
      postDTO = arrpdata.PlanData[0].positionList.PositionDTO[0];
  }
  catch(Exception e)
  {
      System.debug('TCMP5  : '+e.getMessage()+' CALD : '+cald);
      String[] s = new String[]{'TCMP5  : '+e.getMessage()+' CALD : '+cald+' PostDTO : '+postDTO};
        
      return s;
  }

      Integer k = 0;
   try
   {
      nvpair[0] = 'Plan.Name';
    //  nameFields.add('Plan.Name');
      
      nvpair[1] = pdto.name;
      nvpair[2] = 'Plan.Desciption';
      nameFields.add('Plan.Desciption');
      
      nvpair[3] = pdto.description;
    
      nvpair[4] = 'Plan.Effectiveenddate';
    //  nameFields.add('Plan.Effectiveenddate');
      if (pdto.effectiveEndDate != null){
         nvpair[5] = pdto.effectiveEndDate.format();
      }
      nvpair[6] = 'Plan.Effectivestartdate';
    //  nameFields.add('Plan.Effectivestartdate');
      if (pdto.effectiveStartDate != null){
          nvpair[7] = pdto.effectiveStartDate.format();
      }
    
      nvpair[8] = 'Participant.Businessunit';
      nameFields.add('Participant.Businessunit');
      nvpair[9] = partDTO.businessUnit;
      nvpair[10] = 'Participant.Firstname';
    //  nameFields.add('Participant.Firstname');
      nvpair[11] = partDTO.firstName;
      nvpair[12] = 'Participant.Lastname';
    //  nameFields.add('Participant.Lastname');
      nvpair[13] = partDTO.lastName;
    
      nvpair[14] = 'Participant.Hiredate';
      nameFields.add('Participant.Hiredate');
    
      if (partDTO.hireDate != null){
          nvpair[15] = partDTO.hireDate.format();
      }
       
      nvpair[16] = 'Participant.Taxid';
      nameFields.add('Participant.Taxid');
      nvpair[17] = partDTO.taxId;
      
/*      if(partDTO.genericAttributes.GenericAttributeDTO == null)
      {
          System.debug('TCMP6  : CALD : '+cald);
          String[] s = new String[]{'TCMP6  : CALD : '+cald+' PartDTO : '+partDTO+'  Generic Attr :'+partDTO.genericAttributes.GenericAttributeDTO};
          return s;
      }
      else
      {
          count = partDTO.genericAttributes.GenericAttributeDTO.size();
      }
  */
      
      if(partDTO.genericAttributes.GenericAttributeDTO != null)
      {
          count = partDTO.genericAttributes.GenericAttributeDTO.size();

          for (i=0; i < count; i++){
           nvpair[18+k] = 'Participant.Genericattribute' + i + '.Name';
           nameFields.add('Participant.Genericattribute' + i + '.Name');
           nvpair[19+k] = partDTO.genericAttributes.GenericAttributeDTO[i].name;
           nvpair[20+k] = 'Participant.Genericattribute' + i + '.Overridename';
           nameFields.add('Participant.Genericattribute' + i + '.Overridename');
           nvpair[21+k] = partDTO.genericAttributes.GenericAttributeDTO[i].overrideName;
           nvpair[22+k] = 'Participant.Genericattribute' + i + '.Value'; 
           nameFields.add('Participant.Genericattribute' + i + '.Value');
           nvpair[23+k] = partDTO.genericAttributes.GenericAttributeDTO[i].value; 
           k = k+6;
          }
      }//end of if(partDTO.genericAttributes.GenericAttributeDTO != null)    
      
      k = k + 18;
      nvpair[k] = 'Participant.Salary';
      k++;
      
      if(partDTO.salary != null)
      {
          nvpair[k] = partDTO.salary.value;
          k++; 
      }
      else
      {
          nvpair[k] = '';
          k++; 
      }
      
      nvpair[k] = 'Participant.Salaryunittypename';
      nameFields.add('Participant.Salaryunittypename');
      k++;
      if(partDTO.salary != null)
      {
          nvpair[k] = partDTO.salary.unitTypeName;
          k++;
      }
      else
      {
          nvpair[k] = '';
          k++; 
      }
   
      nvpair[k] = 'Position.Description';
      nameFields.add('Position.Description');
      k++;
      nvpair[k] = postDTO.description;
      k++; 
      nvpair[k] = 'Position.Name';
      nameFields.add('Position.Name');
      k++;
      nvpair[k] = postDTO.name;
      k++;
      nvpair[k] = 'Position.Planname';
      nameFields.add('Position.Planname');
      k++;
      nvpair[k] = postDTO.planName;
      k++;
      nvpair[k] = 'Position.Title';
      k++;
      nvpair[k] = postDTO.title;
      k++;
      nvpair[k] = 'Position.Targetcompensation';
      nameFields.add('Position.Targetcompensation');
      k++;
      if(postDTO.targetCompensation != null)
      {
          nvpair[k] = postDTO.targetCompensation.value;
          k++;
      }
      else
      {
          nvpair[k] = '';
          k++;
      }
      
      nvpair[k] = 'Position.Targetcompensationunittype';
      nameFields.add('Position.Targetcompensationunittype');
      k++;

      if(postDTO.targetCompensation != null)
      {
          nvpair[k] = postDTO.targetCompensation.unitTypeName;
          k++;
      }
      else
      {
          nvpair[k] = '';
          k++;
      }
      
      if(postDTO.genericAttributes.GenericAttributeDTO != null)
      {
          count = postDTO.genericAttributes.GenericAttributeDTO.size();
/*      else
      {
          System.debug('TCMP7  : CALD : '+cald);
          String[] s = new String[]{'TCMP7  : CALD : '+cald+' PostDTO : '+postDTO+'  Generic Attr :'+postDTO.genericAttributes.GenericAttributeDTO};
          return s;
      }
*/
          
          for (i=0; i < count; i++){
           nvpair[k] = 'Position.Genericattribute' + i + '.Name';
           nameFields.add('Position.Genericattribute' + i + '.Name');
           k++;
           nvpair[k] = postDTO.genericAttributes.GenericAttributeDTO[i].name;
           k++;
           nvpair[k] = 'Position.Genericattribute' + i + '.Overridename';
           nameFields.add('Position.Genericattribute' + i + '.Overridename');
           k++;
           nvpair[k] = postDTO.genericAttributes.GenericAttributeDTO[i].overrideName;
           k++;
           nvpair[k] = 'Position.Genericattribute' + i + '.Value'; 
           nameFields.add('Position.Genericattribute' + i + '.Value');
           k++;
           nvpair[k] = postDTO.genericAttributes.GenericAttributeDTO[i].value; 
           k++;
          }
       }//if(postDTO.genericAttributes.GenericAttributeDTO != null)

      if(arrpdata.PlanData[0].quotaList.QuotaDTO != null)
      {
       
          count = arrpdata.PlanData[0].quotaList.QuotaDTO.size();
          for (i=0; i < count; i++){
           nvpair[k] = 'Quota' + i + '.Name';
           nameFields.add('Quota' + i + '.Name');
           k++;
           nvpair[k] = arrpdata.PlanData[0].quotaList.QuotaDTO[i].name;
           k++;
           nvpair[k] = 'Quota' + i + '.Description';
           nameFields.add('Quota' + i + '.Description');
           k++;
           nvpair[k] = arrpdata.PlanData[0].quotaList.QuotaDTO[i].description;
           k++;
           nvpair[k] = 'Quota' + i + '.Periodtype'; 
           nameFields.add('Quota' + i + '.Periodtype');
           k++;
           nvpair[k] = arrpdata.PlanData[0].quotaList.QuotaDTO[i].periodtype;
           k++;
           nvpair[k] = 'Quota' + i + '.Periodvalue'; 
           nameFields.add('Quota' + i + '.Periodvalue');
           k++;
           nvpair[k] = arrpdata.PlanData[0].quotaList.QuotaDTO[i].periodValue;
           k++;
           nvpair[k] = 'Quota' + i + '.Value'; 
           nameFields.add('Quota' + i + '.Value');
           k++;
           nvpair[k] = arrpdata.PlanData[0].quotaList.QuotaDTO[i].value;
           k++;
           nvpair[k] = 'Quota' + i + '.Variablename'; 
           nameFields.add('Quota' + i + '.Variablename');
           k++;
           nvpair[k] = arrpdata.PlanData[0].quotaList.QuotaDTO[i].variableName;
           k++;
          }
        }//end of if(arrpdata.PlanData[0].quotaList.QuotaDTO != null)

    if(arrpdata.PlanData[0].territoryList.TerritoryDTO != null)        
    {
          count = arrpdata.PlanData[0].territoryList.TerritoryDTO.size();
          for (i=0; i < count; i++){
           nvpair[k] = 'Terrotory' + i + '.Name';
           nameFields.add('Terrotory' + i + '.Name');
           k++;
           nvpair[k] = arrpdata.PlanData[0].territoryList.TerritoryDTO[i].name;
           k++;
           nvpair[k] = 'Terrotory' + i + '.Description';
           nameFields.add('Terrotory' + i + '.Description');
           k++;
           nvpair[k] = arrpdata.PlanData[0].territoryList.TerritoryDTO[i].description;
           k++;
           nvpair[k] = 'Terrotory' + i + '.Definition'; 
           nameFields.add('Terrotory' + i + '.Definition');
           
           k++;
           nvpair[k] = arrpdata.PlanData[0].territoryList.TerritoryDTO[i].definition;
           k++;
           nvpair[k] = 'Terrotory' + i + '.Variablename'; 
           nameFields.add('Terrotory' + i + '.Variablename');
           k++;
           nvpair[k] = arrpdata.PlanData[0].territoryList.TerritoryDTO[i].variableName;
           k++;
          }
     }//end of if(arrpdata.PlanData[0].territoryList.TerritoryDTO != null)
    
      titlDTO = arrpdata.PlanData[0].titleList.TitleDTO[0];
      nvpair[k] = 'Title.Description';
      nameFields.add('Title.Description');
      k++;
      nvpair[k] = titlDTO.description;
      k++; 
      nvpair[k] = 'Title.Name';
      nameFields.add('Title.Name');
      k++;
      nvpair[k] = titlDTO.name;
    
      k++;
      
      if(titlDTO.genericAttributes.GenericAttributeDTO != null)
      {
          count = titlDTO.genericAttributes.GenericAttributeDTO.size();
          for (i=0; i < count; i++){
           nvpair[k] = 'Title.Genericattribute' + i + '.Name';
           nameFields.add('Title.Genericattribute' + i + '.Name');
           k++;
           nvpair[k] = titlDTO.genericAttributes.GenericAttributeDTO[i].name;
           k++;
           nvpair[k] = 'Title.Genericattribute' + i + '.Overridename';
           nameFields.add('Title.Genericattribute' + i + '.Overridename');
           k++;
           nvpair[k] = titlDTO.genericAttributes.GenericAttributeDTO[i].overrideName;
           k++;
           nvpair[k] = 'Title.Genericattribute' + i + '.Value'; 
           nameFields.add('Title.Genericattribute' + i + '.Value');
           k++;
           nvpair[k] = titlDTO.genericAttributes.GenericAttributeDTO[i].value; 
           k++;
          }
       }//end of if(titlDTO.genericAttributes.GenericAttributeDTO != null)

    if(arrpdata.PlanData[0].fixedValueList.FixedValueDTO != null)
    {
          count = arrpdata.PlanData[0].fixedValueList.FixedValueDTO.size();
          for (i=0; i < count; i++){
           nvpair[k] = 'Fixedvalue' + i + '.Name';
           nameFields.add('Fixedvalue' + i + '.Name');
           k++;
           nvpair[k] = arrpdata.PlanData[0].fixedValueList.FixedValueDTO[i].name;
           k++;
           nvpair[k] = 'Fixedvalue' + i + '.Description';
           nameFields.add('Fixedvalue' + i + '.Description');
           k++;
           nvpair[k] = arrpdata.PlanData[0].fixedValueList.FixedValueDTO[i].description;
           k++;
           nvpair[k] = 'Fixedvalue' + i + '.Value'; 
           nameFields.add('Fixedvalue' + i + '.Value');
           k++;
           nvpair[k] = arrpdata.PlanData[0].fixedValueList.FixedValueDTO[i].value;
           k++;
           nvpair[k] = 'Fixedvalue' + i + '.Variablename'; 
           nameFields.add('Fixedvalue' + i + '.Variablename');
           k++;
           nvpair[k] = arrpdata.PlanData[0].fixedValueList.FixedValueDTO[i].variableName;
           k++;
          }
    }//end of if(arrpdata.PlanData[0].fixedValueList.FixedValueDTO != null)

      Integer subCount = 0;
      Integer j = 0;
    if(arrpdata.PlanData[0].rateTableList.RateTableDTO != null)
    {
          count = arrpdata.PlanData[0].rateTableList.RateTableDTO.size();
          for (i=0; i < count; i++){
           nvpair[k] = 'Ratetable' + i + '.Name';
           nameFields.add('Ratetable' + i + '.Name');
           k++;
           nvpair[k] = arrpdata.PlanData[0].rateTableList.RateTableDTO[i].name;
           k++;
           nvpair[k] = 'Ratetable' + i + '.Description';
           nameFields.add('Ratetable' + i + '.Description');
           k++;
           nvpair[k] = arrpdata.PlanData[0].rateTableList.RateTableDTO[i].description;
           k++;
           nvpair[k] = 'Ratetable' + i + '.Variablename'; 
           nameFields.add('Ratetable' + i + '.Variablename');
           k++;
           nvpair[k] = arrpdata.PlanData[0].rateTableList.RateTableDTO[i].variableName;
           k++;
           
           if(arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel != null)
           {
               subCount = arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel.size();
               for(j=0; j<subCount; j++){
                     nvpair[k] = 'Ratelevel' + j + '.Rate';
                     nameFields.add('Ratelevel' + j + '.Rate');
                     k++;
                     nvpair[k] = arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel[j].rate;
                     k++;
                     nvpair[k] = 'Ratelevel' + j + '.Operator';
                     nameFields.add('Ratelevel' + j + '.Operator');
                     k++;
                     nvpair[k] = arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel[j].operator;
                     k++;
                     nvpair[k] = 'Ratelevel' + j + '.Attainment'; 
                     nameFields.add('Ratelevel' + j + '.Attainment');
                     k++;
                     nvpair[k] = arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel[j].attainment;
                     k++;
               }//end of inner for j
            }//end of if(arrpdata.PlanData[0].rateTableList.RateTableDTO[i].rateLevels.RateLevel != null)
          }//end of outer for i
    }//end of if(arrpdata.PlanData[0].rateTableList.RateTableDTO != null)
  
  }//end of try
  catch(Exception e)
  {
      System.debug('TCMP2  : '+e.getMessage()+' CALD : '+cald);
      String[] s = new String[]{'TCMP2  : '+e.getMessage()+' CALD : '+cald+'   K value : '+k};
        
      return s;
  }
  
  return nvpair;
}//end of method getPlanNamearr()


    static testMethod void testCase() 
    {
        TCMPCallidusCom1.ArrayOfPlanData  arrpdata = new TCMPCallidusCom1.ArrayOfPlanData();
        getPlanNamearr('','','');
        getPlanNameMap('a0E40000000knbh', '');
        
    }
    
}